package com.study.spmongodb.book.wwj.char02;

/**
 * @author study
 * @version 1.0
 * @date 2020/11/24 15:13
 */
public class DaemonThread {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        //设置守护进程|main进程结束生命周期后，JVM也随之退出，当然thread线程也会结束
        thread.setDaemon(true);
        thread.start();
        Thread.sleep(2_000L);
        System.out.println("main thread finished lifecycle.");
    }
}
